<?php
class ModelTotalShipping extends Model {
	public function getTotal(&$total_data, &$total, &$taxes, $status = 0) { 
		if ($this->cart->hasShipping() && isset($this->session->data['shipping_method']) && $this->config->get('shipping_status')) {                        
			if($this->cart->getSubTotal() > 0){
				$shipping = $this->session->data['shipping_method']['cost'];
                if($this->session->data['shipping_method']['id'] == 'flat.flat' && isset($this->session->data['country_code'])){
                    if ($this->session->data['country_code'] == 'DK') {
                        if(isset($total_data['subtotal']) && ($this->config->get('flat_free_shipping') > 0) && ($total_data['subtotal']['value'] > $this->config->get('flat_free_shipping'))){
                            $shipping = 0;
                        }
                    }
                    else{
                        $shipping = $this->config->get('flat_cost1');
                    }
                }
			}
			else{
				$shipping = 0;
			}

            $total_data['shipping'] = array( 				
        		'title'      => 'Fragt',
        		'text'       => $this->currency->formatPrice($shipping),
        		'value'      => $shipping, //$this->session->data['shipping_method']['cost'],
				'sort_order' => $this->config->get('total_sort_order') - 1, //$this->config->get('shipping_sort_order'),
				'total_code' => '',
			);

			if ($this->session->data['shipping_method']['tax_class_id']) {
				if (!isset($taxes[$this->session->data['shipping_method']['tax_class_id']])) {
					$taxes[$this->session->data['shipping_method']['tax_class_id']] = $this->session->data['shipping_method']['cost'] / 100 * $this->tax->getRate($this->session->data['shipping_method']['tax_class_id']);
				} else {
					$taxes[$this->session->data['shipping_method']['tax_class_id']] += $this->session->data['shipping_method']['cost'] / 100 * $this->tax->getRate($this->session->data['shipping_method']['tax_class_id']);
				}
			}			
            
            $total += $shipping; //$this->session->data['shipping_method']['cost'];
		}
	}
	
	public function getTotalShipping(&$total_data, &$total, &$taxes) {
		if ($this->cart->hasShipping() && isset($this->session->data['shipping_method']) && $this->config->get('shipping_status')) {
			$total_data[] = array( 
				'code'       => 'shipping', 
        		'title'      => $this->session->data['shipping_method']['title'] . ':',
        		'text'       => $this->currency->format($this->session->data['shipping_method']['cost']),
        		'value'      => $this->session->data['shipping_method']['cost'],
				'sort_order' => $this->config->get('shipping_sort_order')
			);

			if ($this->session->data['shipping_method']['tax_class_id']) {
				if (!isset($taxes[$this->session->data['shipping_method']['tax_class_id']])) {
					$taxes[$this->session->data['shipping_method']['tax_class_id']] = $this->session->data['shipping_method']['cost'] / 100 * $this->tax->getRate($this->session->data['shipping_method']['tax_class_id']);
				} else {
					$taxes[$this->session->data['shipping_method']['tax_class_id']] += $this->session->data['shipping_method']['cost'] / 100 * $this->tax->getRate($this->session->data['shipping_method']['tax_class_id']);
				}
			}
			
			$total += $this->session->data['shipping_method']['cost'];
		}			
	}
}
?>